package com.meng.mmlive.ui.adapter;

import android.content.Context;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.TextView;

import com.lqr.adapter.LQRAdapterForRecyclerView;
import com.lqr.adapter.LQRViewHolderForRecyclerView;
import com.lqr.emoji.MoonUtils;
import com.meng.mmlive.R;
import com.meng.mmlive.utils.TimeUtils;

import java.util.List;

import io.rong.imlib.model.Conversation;
import io.rong.message.TextMessage;

/**
 * Created by Administrator on 2017/5/15.
 */

public class RecentConversationAdapter extends LQRAdapterForRecyclerView<Conversation>{
    public RecentConversationAdapter(Context context, List<Conversation> data, int defaultLayoutId) {
        super(context, data, defaultLayoutId);
        this.context = context;
    }
    Context context;
    @Override
    public void convert(LQRViewHolderForRecyclerView helper, Conversation item, int position) {
        helper.setText(R.id.tvDisplayName,"昵称:"+item.getTargetId())
        .setText(R.id.tvTime, TimeUtils.getMsgFormatTime(item.getReceivedTime()));
        TextView tvContent = helper.getView(R.id.tvContent);
        MoonUtils.identifyFaceExpression(context, tvContent, ((TextMessage) item.getLatestMessage()).getContent(), ImageSpan.ALIGN_BOTTOM);
        helper.setBackgroundColor(R.id.flRoot, item.isTop() ? R.color.gray8 : android.R.color.white)
                .setText(R.id.tvCount, item.getUnreadMessageCount() + "")
                .setViewVisibility(R.id.tvCount, item.getUnreadMessageCount() > 0 ? View.VISIBLE : View.GONE);
    }
}
